﻿using System.Diagnostics;

namespace AiMachineControl.Common
{
    /// <summary>
    /// 硬件信息操作类
    /// </summary>
    public class HardwareInfo
    {
        /// <summary>
        /// 获取当前系统内存使用情况
        /// </summary>
        public static float GetMemoryInfo()
        {
            PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            float availableMB = ramCounter.NextValue();
            //Console.WriteLine("系统可用内存：{0} MB", availableMB);
            return availableMB;
        }

        /// <summary>
        /// 获取当前系统CPU使用情况
        /// </summary>
        public static float GetCpuInfo()
        {
            PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            float cpuUsage = cpuCounter.NextValue();
            System.Threading.Thread.Sleep(1000);
            cpuUsage = cpuCounter.NextValue();
            //Console.WriteLine("CPU 使用率: {0}%", cpuUsage);
            return cpuUsage;
        }

        /// <summary>
        /// 获取当前系统GPU使用情况
        /// </summary>
        public static void GetGpuInfo() 
        { 
        
        }

        /// <summary>
        /// 获取当前系统硬盘使用情况
        /// </summary>
        public static void GetHardDiskInfo()
        {
            // 获取硬盘使用情况
            foreach (DriveInfo drive in DriveInfo.GetDrives())
            {
                if (drive.IsReady)
                {
                    Console.WriteLine("{0} 硬盘使用情况：", drive.Name);
                    Console.WriteLine("总容量：{0} GB", drive.TotalSize / 1024 / 1024 / 1024);
                    Console.WriteLine("已使用容量：{0} GB", (drive.TotalSize - drive.AvailableFreeSpace) / 1024 / 1024 / 1024);
                    Console.WriteLine("可用容量：{0} GB", drive.AvailableFreeSpace / 1024 / 1024 / 1024);
                }
            }
        }

    }
}
